<%@ page import="uniLearn.control.*"%>
<%@ page import="uniLearn.data.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%!
	//Define Error Message
	static final String ERR_LOGIN_FAIL = "Incorrect name or password, Please login again.";
	
	//Define Session attribute name
	static final String SESSION_LOGIN_USER = "loginUser";
	
	//Define reauest parameter name
	static final String PAR_LOGIN_NAME = "login_name";
	static final String PAR_PASSWORD = "password";
	
	//Define Redirect URL
	static final String URL_STUDENT = "Student/Student_index.jsp";
	static final String URL_STAFF = "Staff/Staff_index.jsp";
	static final String URL_ADMIN = "Admin/admin_index.jsp";
	static final String URL_HOMEPAGE = "../index.html";
	
	//shared function
	static boolean loginedChecking(HttpSession session, UsersType reqType) {
		Object loginUser = session.getAttribute(SESSION_LOGIN_USER);
		if(!objectChecking(loginUser, Users.class))
			return false;
		
		return ((Users)loginUser).getUserType() == reqType;
	}
	
	static boolean objectChecking(Object sessionValue, Class targetClass) {
		if(sessionValue == null)
			return false;
		
		return targetClass.isInstance(sessionValue);
	}
%>